#
# Cookbook Name:: logstash
# Recipe:: config_for_app
#
# Copyright 2013, IBM
#
# All rights reserved - Do Not Redistribute
#

cuser = node[:chef][:user]
cgroup = node[:chef][:group]
deployment = node[:deployment]

include_recipe "logstash::install"

startinstr "Config logstash"

template "/opt/#{node[:logstash][:version]}/shipper.conf" do
  source "shipper-app.conf.erb"
  owner cuser
  group cgroup
  mode 0755
  variables( :logstash_server => "#{node['logstash']['host_ip']}",:logstash_server_port => "#{node['logstash']['host_port']}", :logstash_logPath => "#{node['logstash']['applogPath']}",:logstash_dir => "#{node['logstash']['dir']}"  )
  action :create
end

template "/etc/init.d/logstashservice" do
  source "logstashservice.erb"
  owner "root"
  group "root"
  mode 0755
  variables( :logstash_dir => "#{node['logstash']['dir']}",:logstash => "#{node[:logstash][:version]}",:java_home => "#{node[:java7][:install_dir]}"  )
  action :create
end

bash "Start logstash service" do
  user cuser
  group cgroup
  cwd "/etc/init.d"
  code <<-EOH
      sudo service logstashservice start
  EOH
end

stopinstr "Config logstash"
